package com.taotao.item.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.taotao.item.pojo.Item;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemDesc;
import com.taotao.service.ItemService;

/**
 * 查看商品详细信息
 * @author Administrator
 *
 */
@Controller
public class Itemcontroller {

	@Autowired
	private ItemService itemService;
	
	//item/{itemId}
	@RequestMapping("/item/{itemId}")
	public String item(@PathVariable("itemId") long itemId,Model model) {
		//获得商品
		TbItem tbItem = itemService.getItemById(itemId);
		//或得商品描述
		TbItemDesc desc = itemService.getDescById(itemId);
		//封装商品
		Item item = new Item(tbItem);
		
		//返回数据和视图
		model.addAttribute("item", item);
		model.addAttribute("itemDesc", desc);
		return "item";
	}
}
